<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\BaseController;
use app\middleware\AdminAuth;
use app\model\Admin;
use app\model\Cdkey;
use app\model\Config;
use app\model\Invite;
use app\model\Notice;
use app\model\Profit;
use app\model\Task;
use app\model\Transfer;
use app\model\TransferList;
use app\model\User;
use app\model\Version;
use app\validate\UserReg;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Session;
use think\facade\View;
use think\Request;


use app\model\Phonecharge;
use app\model\PhonechargeList;

class Rule extends BaseController
{
    protected $middleware = [
        AdminAuth::class
    ];



    /*
   * 列表
   */
    public function getList()
    {
//        $page = input('page', 1);
//        $limit = input('limit', 10);
//        $keyword = input('keyword');
//
//        $where = [];
//
//
//        $list = Db::name('rule')
//            ->where($where)
//            ->order('id desc')
//            ->paginate([
//                'list_rows' => $limit,
//                'page' => $page,
//            ],false,['query'=>request()->param()])->toArray();
//
//        $data  =[
//            'data' => $list['data'],
//            'count' => $list['total'],
//            'code' => 1,
//            'msg' => 'success'
//        ];


//        return json($data);
    }


    public function index()
    {
        $info = Db::name('rule')->where('id', 1)->find();
        View::assign('info', $info);
        return View::fetch();
    }

    /*
     * 添加
     */
    public function add()
    {
        $data = input('post.');
        $ret = Db::name('rule')->insert($data);
        if($ret){
            return success();
        }
        return error();
    }

    /*
     * 编辑
     */
    public function edit()
    {



        if(request()->isPost()){
            $data = input('post.');//$data['id']
            $ret = Db::name('rule')->where('id',1)->update($data);
            if($ret){
                return success();
            }
            return error();
        }
    }

    /*
     * 删除
     */
    public function del()
    {
        $id = input('id');
        $ids = input('ids');
        if($id){
            $ret = Db::name('rule')->where('id',$id)->delete();
            if($ret){
                return success();
            }
            return error();
        }
        if($ids){
            $ret = Db::name('rule')->where('id','in',$ids)->delete();
            if($ret){
                return success();
            }
            return error();
        }
    }



}